<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="pony.model.*" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>  <%-- 使用JSTL標籤函式庫 --%>
<%@ taglib prefix="pony" uri="/WEB-INF/TLDs/simple.tld" %>
<%@ taglib prefix="headfirst" uri="/WEB-INF/TLDs/simple.tld" %>
<%-- 使用自定的TLD --%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>A Testing JSP</title>
	<style type="text/css">
		body {
			color: #CC6633;  /* 設定body中的內文的顏色 */
			background-color: #CCCC66;  /* 設定body的背景顏色 */
			font-family: Monaco; 
			font-size: 16px;
		}
		
		span.keywords {
			font-family: Monaco; 
			font-size: 16px;
			color: #660066;
		}
	</style>
	
</head>

<body>
	<center>
	You choose ${param.color}.<br />
	<% 
		// 注意! 在JSP中，不可以有巢狀的JSP Scripting元素!
		int i = 0;
		int j = i + 4;
		pageContext.setAttribute("bigDogAge", j + 2);  // 小心! 這裡對第二個引數有使用autoboxing機制!
		// 故意先設定一個Page作用域的Attribute
		
		String color = new String("gray");
		String dogColor = "brown";
		String dogName = "Lenny";
		
		pageContext.setAttribute("bigDogName", dogName);
		// 故意先設定一個Page作用域的Attribute
		
		pageContext.setAttribute("bigDogColor", dogColor + " & " + color);
		// 故意先設定一個Page作用域的Attribute
		
		Dog bigDog = new Dog();
		String includeURL = "/WEB-INF/jsp/includePage1.jsp";
	%>
	
	<jsp:useBean id="bigdog" class="pony.model.Dog" scope="page">
		<jsp:setProperty name="bigdog" property="name" value="${pageScope.bigDogName}" />
		
		<jsp:setProperty name="bigdog" property="color" 
			value="<%= pageContext.getAttribute(\"bigDogColor\") %>" />
			<%-- 注意，以上故意在JSP標準動作標籤中，使用了JSP Expression來設定標籤屬性值 --%>
			<%-- value='<%= pageContext.getAttribute("bigDogColor") %>' />  外層用單引號! --%>
			<%-- 
				以上的機制叫做: JSP Request-time attribute 執行時期標籤屬性
				此機制只允許，Expression出現在JSP action標籤之中，用來設定標籤屬性!
			--%>
		<jsp:setProperty name='bigdog' property='age' value='<%= j+1+1  %>' />
	</jsp:useBean>
	
	
	<jsp:include page="<%= includeURL %>" /><br />
	Here is an another BIG dog...<br />
	<p>
		Its name called <span class='keywords'><c:out value="${bigdog.name}">黃黃</c:out>.</span><br />
		The color of the BIG dog is <span class='keywords'><c:out value='${bigdog.color}'>yellow</c:out></span>.<br />
		The age of the BIG dog is <span class='keywords'><c:out value='${bigdog.age}'>2</c:out></span>.<br />
	</p>
	
	<%= ((Dog)pageContext.getAttribute("bigdog")).toString() %><br />
	<% 
		String strs = ((Dog)pageContext.getAttribute("bigdog")).toString(); 
		pageContext.setAttribute("strs", strs);
	%>
	
	${headfirst:showString(strs) }<br />
	<i style="color:#0033FF;">This is also another result of EL function: ${pony:rollIt() }</i>
	
	</center>
</body>
</html>